#include<vector>
#include<map>
#include<algorithm>
using namespace std;

class Solution {
public:
    bool isNStraightHand(vector<int>& hand, int W) {
        if (hand.size() % W != 0) return false;
        map<int, int>helper_map;
        for (auto& it : hand)
            ++helper_map[it];
        for (auto it = helper_map.begin(); it != helper_map.end(); ++it) {
            while (it->second > 0) {
                --it->second;
                for (int i = 1; i < W; ++i) {
                    if (helper_map.find(it->first + i) != helper_map.end() &&
                        helper_map[it->first + i] != 0) {
                        --helper_map[it->first + i];
                    }
                    else
                        return false;
                }
            }
        }
        return true;
    }
};